package com.demo.websocketbarrage.entity;

public class Site {

    private Integer x;
    private Integer y;


    public Site() {
    }

    public Site(Integer x, Integer y) {
        this.x = x;
        this.y = y;
    }

    public Integer getX() {
        return x;
    }

    public void setX(Integer x) {
        this.x = x;
    }

    public Integer getY() {
        return y;
    }

    public void setY(Integer y) {
        this.y = y;
    }


//位置移动
    public void turnUp(){
        this.y--;
    }
    public void turnDown(){
        this.y++;
    }
    public void turnLeft(){
        this.x--;
    }
    public void turnRight(){
        this.x++;
    }


//检查边界
    public boolean checkUp(Integer minY){
        if(this.y-1 < minY)
            return false;
        return true;
    }
    public boolean checkDown(Integer maxY){
        if (this.y+1>maxY)
            return false;
        return true;
    }
    public boolean checkLeft(Integer minX){
        if (this.x-1<minX)
            return false;
        return true;
    }
    public boolean checkRight(Integer maxX){
        if (this.x+1>maxX)
            return false;
        return true;
    }

//移动位置 （集成检查）
    public void checkUpAndTurn(Integer minY){
        if (this.checkUp(minY))
            this.turnUp();
    }
    public void checkDownAndTurn(Integer maxY){
        if (this.checkDown(maxY))
            this.turnDown();
    }
    public void checkLeftAndTurn(Integer minX){
        if (this.checkLeft(minX))
            this.turnLeft();
    }
    public void checkRightAndTurn(Integer maxX){
        if (this.checkRight(maxX))
            this.turnRight();
    }
}
